package com.fandy.struts.action;

import java.sql.ResultSet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.fandy.struts.DAL.DALGoodsInfo;
import com.fandy.struts.form.FormSearch;
import com.fandy.struts.util.MappingForward;

public class ActionSearch extends DispatchAction{

	/* (non-Javadoc)
	 * @see org.apache.struts.actions.DispatchAction#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
	
		ActionForward af = null;
		
		FormSearch fs = (FormSearch) form; 
		
		ResultSet rs = GetSearchResult(fs.AnalysisKeyWord());
		 
		request.getSession().setAttribute("ResultSet", rs );
		
		if(request.getSession().getAttribute("UserInfo")!=null)
		{
			af = mapping.findForward(MappingForward.Membership);
		}
		else
		{
			af = mapping.findForward(MappingForward.Visitor);
			
		}
		return af;
		
	}

	private ResultSet GetSearchResult( String keyword )
	{
		
		return  new DALGoodsInfo().Search(keyword) ;
	}
	
}
